home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
CC_C
/
1116.ZIP
/
TOOLKIT.ARC
/
SOUNDEX.C
< prev
next >
Wrap
Text File
|
1979-12-31
|
4KB
|
94 lines
/*****************************************************************/
/* */
/* soundex.c soundex algorithm implemented in smallc */
/* */
/* written by Wayne Pearson RD2 Montpelier, Vt 05602 */
/* */
/*****************************************************************/
main()
{
inscreen(); /* make a data entry screen */
workfile(); /* make a work file to hold string */
/* call soundex() from workfile() to pass namelen */
}
inscreen()
{
clrscreen();
putchar(13);
puts(" Enter the name to be converted: ");
}
workfile()
{
int *outf;
char name;
int namelen;
outf = fopen("soundex.wrk","w");
namelen = 0;
while (name != ' ') /* space ends input */
{
name = getchar();
name = putc(name,outf);
++namelen;
}
fclose(outf);
putchar(13); putchar(13);
soundex(); /* make soundex code of user input */
}
soundex()
{
int *inf;
char codename, oldname;
int namelen, lcv;
puts(" Soundex equivalent: ");
lcv = 0;
inf = fopen("soundex.wrk","r");
codename = getc(codename,inf);
codename = putchar(codename);
++lcv;
while (lcv < namelen)
{
oldname = codename;
codename = getc(codename,inf);
if (oldname == codename) codename = '*';
if ((codename == 'B')|(codename == 'b')|
(codename == 'F')|(codename == 'f')|
(codename == 'P')|(codename == 'p')|
(codename == 'V')|(codename == 'v'))
codename = '1';
if ((codename == 'C')|(codename == 'c')|
(codename == 'G')|(codename == 'g')|
(codename == 'J')|(codename == 'j')|
(codename == 'K')|(codename == 'k')|
(codename == 'Q')|(codename == 'q')|
(codename == 'S')|(codename == 's')|
(codename == 'X')|(codename == 'x')|
(codename == 'Z')|(codename == 'z'))
codename = '2';
if ((codename == 'D')|(codename == 'd')|
(codename == 'T')|(codename == 't'))
codename = '3';
if ((codename == 'L')|(codename == 'l'))
codename = '4';
if ((codename == 'M')|(codename == 'm')|
(codename == 'N')|(codename == 'n'))
codename = '5';
if ((codename == 'R')|(codename == 'r'))
codename = '6';
if ((codename == '1')|(codename == '2')|
(codename == '3')|(codename == '4')|
(codename == '5')|(codename == '6'))
codename = putchar(codename);
++lcv;
}
fclose(inf);
putchar(13);
}